package com.campus.common.message;

import com.campus.common.vo.Classroom;
import com.campus.common.vo.Course;
import com.campus.common.vo.Student;
import com.campus.common.vo.Teacher;

import java.io.Serializable;
import java.util.List;

/**
 * 管理员课程/班级操作响应（泛型版 + 兼容老接口）
 */
public class AdminCourseResponse<T> implements Serializable {
    private boolean success;    // 操作是否成功
    private String message;     // 返回信息
    private T data;             // 单个对象（课程 / 班级 / 学生 / 教师）
    private List<T> dataList;   // 对象列表（课程列表 / 学生列表 / 教师列表等）

    public AdminCourseResponse() {}

    public AdminCourseResponse(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    // 构造函数：单个对象
    public AdminCourseResponse(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    // 构造函数：对象列表
    public AdminCourseResponse(boolean success, String message, List<T> dataList) {
        this.success = success;
        this.message = message;
        this.dataList = dataList;
    }

    // ===== Getter / Setter =====
    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }

    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }

    public T getData() { return data; }
    public void setData(T data) { this.data = data; }

    public List<T> getDataList() { return dataList; }
    public void setDataList(List<T> dataList) { this.dataList = dataList; }

    // ===== 兼容老接口的方法（向下兼容，不强制使用） =====
    @SuppressWarnings("unchecked")
    public List<Course> getCourses() {
        return (List<Course>) dataList;
    }

    @SuppressWarnings("unchecked")
    public Course getCourse() {
        return (Course) data;
    }

    @SuppressWarnings("unchecked")
    public Classroom getClassroom() {
        return (Classroom) data;
    }

    @SuppressWarnings("unchecked")
    public Student getStudent() {
        return (Student) data;
    }

    @SuppressWarnings("unchecked")
    public List<Student> getStudents() {
        return (List<Student>) dataList;
    }

    // ✅ 新增 Teacher 支持
    @SuppressWarnings("unchecked")
    public Teacher getTeacher() {
        return (Teacher) data;
    }

    @SuppressWarnings("unchecked")
    public List<Teacher> getTeachers() {
        return (List<Teacher>) dataList;
    }
}
